<?php
namespace app\admin\model;

use think\Model;

class Account extends Model{



    public function getCostTypeAttr($value)
    {
        //1学币 2学费 3教师费用 4推荐奖金 5管理费用 6专项费用 7教具费用 8合作费用 9教务费用 10教室费用 11重上费用
        $cost_type = [
            1=>'学币',
            2=>'学费',
            3=>'教师费用',
            4=>'推荐奖金',
            5=>'管理费用',
            6=>'专项费用',
            7=>'教师费用',
            8=>'合作费用',
            9=>'教务费用',
            10=>'教室费用',
            11=>'重上费用',
        ];

        return $cost_type[$value];
    }

    public function getStatusAttr($value){
        $status = [
            0 => '失败',
            1 => '成功',
            2 => '其他',

        ];
        return $status[$value];
    }

    /*
     * 流水总记录数
     * @author 巫玉梅 <1120504614@qq.com>
     * @return
     */
    public function getAll(){
        $order="";
        $keywords = trim(input('get.keywords'));
        if(!empty($keywords)){
            $where = ['u.full_name|u.tel|u.username'=> ['like', "%{$keywords}%"]];
        }else{
            $where = [];
        }

        $account = $this
            ->alias('ac')
            ->join('user u', 'ac.user_id=u.id', 'LEFT')
            ->field('ac.*,ac.cost_description,ac.id,ac.record_time,
                    ac.cost_type,u.tel,u.full_name')
            ->where($where)
            ->order($order)
            ->select();
        if($account){
            foreach($account as $k => $v){
                $account[$k] = $v->toArray();
            }
        }
        return $account;
    }

    /**
     * 查询总记录数
     * @author 巫玉梅 <1120504614@qq.com>
     * @return
     */
    public function getCount(){
        $order="";
        $keywords = trim(input('get.keywords'));
        if(!empty($keywords)){
            $where = ['u.full_name|u.tel|u.username'=> ['like', "%{$keywords}%"]];
        }else{
            $where = [];
        }

        $count = $this
            ->alias('ac')
            ->join('user u', 'ac.user_id=u.id', 'LEFT')
            ->field('ac.*,ac.cost_description,ac.id,ac.record_time,ac.cost_type,
                    u.tel,u.full_name')
            ->where($where)
            ->order($order)
            ->count();
        return $count;
    }

    /**
     * 查询详情
     * @author 巫玉梅 <1120504614@qq.com>
     * @return
     */
    public function getOne(){
        $info  = $this
            ->alias('ac')
            ->join('user u', 'ac.user_id=u.id', 'LEFT')
            ->field('ac.*,ac.cost_description,ac.id,ac.record_time,
                    ac.cost_type,u.tel,u.full_name')
            ->find();
        if($info){
            $info = $info ->toArray();
        }
        return $info;
    }
}